<template>
  <basic-container :btn-flag="true">
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>

      <div style="float: right;margin-right: 17px;margin-top: 52px;">
        <el-button type="success" @click.stop="addEvaluation()">上传</el-button>
      </div>
      <div class="card-body">
        <avue-crud :data="resultListData"
                   :option="tableoption"
                   :page="page"
                   :table-loading="tableLoading"
                   @on-load="getResultList"
                   @refresh-change="refreshChange"
                   @search-change="searchChange"
                   class="menu-min-height">
        </avue-crud>
      </div>

      <el-dialog title="新增评估" :visible.sync="dialogVisible" width="800px">
        <el-form
          label-width="130px"
          :model="projectForm"
          style="padding-right: 30px;"
          :rules="versionrules"
          ref="projectForm"
        >
          <el-row style="font-weight: 600">
            <el-col :span="11">
              <el-form-item class="form-item-release" label="评估名称 :" prop="title">
                <el-input
                  type="text"
                  placeholder="请输入修改说明"
                  v-model="projectForm.title"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="form-group-file">
            <span class="form-label-file">附件 :</span>
            <el-upload
              class="upload-demo"
              action="string"
              :http-request="fileUploadRequest"
              :on-preview="fileHandlePreview"
              :on-remove="fileHandleRemove"
              :file-list="fileTypeIds['附件']"
              :auto-upload="true">
              <el-button slot="trigger" size="small" type="primary" style="margin-left: 10px;">点击上传</el-button>
              <!--<div slot="tip" class="el-upload__tip">上传工作方案、工作计划等相关材料</div>-->
            </el-upload>
          </div>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="addEvaluationYes()">确定</el-button>
          <el-button @click="cancel()">取 消</el-button>
        </div>
      </el-dialog>

      <el-dialog title="评估详情" :visible.sync="evaluationDialogVisible" width="70%">
        <bostech-detail :detail-data="evaluationDetailData"></bostech-detail>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="evaluationDialogVisible = false">确 定</el-button>
        </div>
      </el-dialog>

    </div>
  </basic-container>
</template>

<script>
  import {getEvaluationList, addEvaluation} from "@/api/pim/pim";
  import fileTypeMixin from "@/mixins/fileTypeMixin";
  import getEvaluationDetail from "@/mixins/pim/getEvaluationDetail";

  export default {
    name: "evaluationList",
    mixins: [fileTypeMixin, getEvaluationDetail()],
    created() {
      window.evaluationDetai = this.evaluationDetai
    },
    data() {
      return {
        headerData: {
          title: '监测评估'
        },
        fileType: '附件',
        resultListData: [],
        tableLoading: false,
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        tableoption: {
          page: true,
          menuWidth: 1,
          addBtn: false,
          editBtn: false,
          addRowBtn: false,
          indexLabel: "序号",
          index: true,
          indexWidth:70,
          cellBtn: false,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn: false,
          keyId: "id",
          column: [
            {
              label: "评估名称",
              width: 350,
              prop: "title",
              cell: true,
              search: true,
              formatter: function (row, value, label, column) {
                return '<a style="cursor: pointer;" onclick="evaluationDetai(\'' + row.evaluationId + '\')">' + value + '</a>';
              },
            },
            {
              label: "规划成果名称",
              width: 250,
              prop: "achievementTitle",
              cell: true
            },
            {
              label: "创建人",
              prop: "createNickname",
              cell: true
            },
            {
              label: "创建时间",
              prop: "createTime",
              cell: true,
              formatter: function (row, value, label, column) {
                return value.split(' ')[0];
              },
            },
          ]
        },
        projectForm: {},
        dialogVisible: false,
        evaluationDialogVisible: false
      }
    },
    methods: {
      searchChange() {

      },
      refreshChange() {

      },
      getResultList(page) {
        this.tableLoading = true;
        getEvaluationList(Object.assign({
          current: page.currentPage,
          size: page.pageSize,
          achievementId: this.$route.query.achievementId
        },)).then(response => {
          this.resultListData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false
        })
      },
      evaluationDetai(evaluationId) {
        this.getDetailData_evaluation(evaluationId);
        this.evaluationDialogVisible = true;
      },
      cancel() {
        this.dialogVisible = false;
      },
      // 新增评估弹窗
      addEvaluation() {
        this.dialogVisible = true
      },
      // 新增评估确定
      addEvaluationYes() {
        this.$refs.projectForm.validate(valid => {
          if (valid) {
            this.$confirm("确定新增评估吗?", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }).then(() => {
              this.projectForm.achievementId = this.$route.query.achievementId;
              //将多个相关材料的附件id拼成逗号隔开的字符串放在 this.projectForm.fileId 中
              this.projectForm.fileIds = this.getFileIds(this.fileTypeIds[this.fileType]);
              addEvaluation(this.projectForm).then(response => {
                if (response.data.code == 0) {
                  this.$notify({
                    title: "成功",
                    message: "新增成功",
                    type: "success",
                    duration: 2000
                  });
                  this.dialogVisible = false;
                  this.getResultList(this.page)
                }
              })
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
